package com.bhs.sansong.adapter;

import android.text.TextUtils;

import androidx.annotation.NonNull;

import com.bhs.sansong.R;
import com.bhs.sansong.bean.DedicatedLineBean;
import com.bhs.sansong.bean.PriceBean;
import com.bhs.sansong.utils.MyUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.google.gson.Gson;

public class DedicatedLineAdapter extends BaseQuickAdapter<DedicatedLineBean, BaseViewHolder> {

    public DedicatedLineAdapter() {
        super(R.layout.item_dedicated_line2);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, DedicatedLineBean item) {
        helper.setText(R.id.tv_line_name, item.getStart_city() + "—" + item.getEnd_city());

        helper.addOnClickListener(R.id.btn_range_transport);
        PriceBean priceBean = new Gson().fromJson(item.getFast_price_json(), PriceBean.class);
        helper.setText(R.id.tv_express_1to1, TextUtils.isEmpty(priceBean.P1) ? "" : String.format("%s元", priceBean.P1));
        helper.setText(R.id.tv_express_1to3, TextUtils.isEmpty(priceBean.P3) ? "" : String.format("%s元", priceBean.P3));
        helper.setText(R.id.tv_express_1to6, TextUtils.isEmpty(priceBean.P6) ? "" : String.format("%s元", priceBean.P6));
        helper.setText(R.id.tv_express_1to10, TextUtils.isEmpty(priceBean.P10) ? "" : String.format("%s元", priceBean.P10));
        PriceBean priceBean2 = new Gson().fromJson(item.getGeneral_price_json(), PriceBean.class);
        helper.setText(R.id.tv_general_1to1, TextUtils.isEmpty(priceBean2.P1) ? "" : String.format("%s元", priceBean2.P1));
        helper.setText(R.id.tv_general_1to3, TextUtils.isEmpty(priceBean2.P3) ? "" : String.format("%s元", priceBean2.P3));
        helper.setText(R.id.tv_general_1to6, TextUtils.isEmpty(priceBean2.P6) ? "" : String.format("%s元", priceBean2.P6));
        helper.setText(R.id.tv_general_1to10, TextUtils.isEmpty(priceBean2.P10) ? "" : String.format("%s元", priceBean2.P10));
        helper.setText(R.id.tv_genera_aging, String.format("%s-%s天", item.getGeneral_day_min(), item.getGeneral_day_max()));
        helper.setText(R.id.tv_express_aging, String.format("%s-%s天", item.getFast_day_min(), item.getFast_day_max()));

            helper.addOnClickListener(R.id.tv_line_name);
            helper.addOnClickListener(R.id.iv_status);
            helper.addOnClickListener(R.id.fl_shipping_phone);
            helper.addOnClickListener(R.id.fl_phone_number);
            helper.setGone(R.id.ll_shrink, item.isChecked());
            helper.setImageResource(R.id.iv_status, item.isChecked() ? R.mipmap.ic_zhankai : R.mipmap.ic_shouqi);
            helper.setText(R.id.tv_line_manager, item.getLine_contact());
            helper.setText(R.id.tv_phone_number, item.getLine_mobile());
            if(!MyUtils.isEmpty(item.getOutlets_list())) {
                helper.setText(R.id.tv_shipping_company, item.getOutlets_list().get(0).getOutlets_name());
                helper.setText(R.id.tv_shipping_phone, item.getOutlets_list().get(0).getOutlets_mobile());
                helper.setText(R.id.tv_ship_address, item.getOutlets_list().get(0).getOutlets_address());
            }
            helper.setGone(R.id.ll_quoted_price, item.getPrice_show_status() == 1);
            helper.setText(R.id.tv_principal, item.getPrice_show_status() == 1 ? "运费报价" : "暂无报价");
            helper.setGone(R.id.tv_hint, item.getPrice_show_status() == 1);
        }


}
